import { BeforeInsert, Column, Entity, PrimaryColumn } from 'typeorm';
import { nanoid } from 'nanoid';

@Entity()
export class User {
  @PrimaryColumn({
    type: 'varchar',
    length: 21,
  })
  id: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: false,
  })
  company: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: false,
  })
  name: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: false,
  })
  number: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: true,
  })
  group: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: true,
  })
  category: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: true,
  })
  works: string;

  @Column({
    type: 'int',
    nullable: false,
  })
  status: number;

  @Column({
    type: 'datetime',
    nullable: true,
  })
  updatedStatusAt: Date;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
  })
  personalUrl: string;

  @Column({
    type: 'datetime',
    nullable: true,
  })
  updatedPersonalAt: Date;

  @Column({
    type: 'varchar',
    length: 255,
    nullable: true,
  })
  raceUrl: string;

  @Column({
    type: 'datetime',
    nullable: true,
  })
  updatedRaceAt: Date;

  @BeforeInsert()
  generateId() {
    this.id = nanoid(21);
  }
}
